import sys
import numpy as np

sys.path.append("../utils")

from utils import OpRunner, compare
import time


def main():
    func = OpRunner("./build/libop.so", 2, pint_time=True)
    minvalue = 10
    maxvalue = -10
    shape = [1024 , 1024]
    # for dtype in [np.float16, np.float32, np.int32, np.int8]:
    for dtype in [np.float16, np.float32]:
        input_x = np.random.uniform(minvalue, maxvalue, shape).astype(dtype)
        output = np.zeros(shape, dtype=dtype)
        attr = 1.702
        attr_opp = 0 - attr
        attr_half = attr / 2
        abs_x = input_x
        mul_abs_x = abs_x * attr_opp # -1.702 * |x|
        exp_abs_x = np.exp(mul_abs_x) # e^(-1.702 * |x|)
        div_down = exp_abs_x + 1.0 # 1 + e^(-1.702 * |x|)
        pn_x = input_x - abs_x  # x - |x|
        mul_pn_x = pn_x * attr_half  # (x - |x|) * 0.851
        exp_pn_x = np.exp(mul_pn_x) # e^((x - |x|) * 0.851)
        div_up = input_x * exp_pn_x # x * e^((x - |x|) * 0.851)
        golden = div_up / div_down # x * e^((x - |x|) * 0.851) / (1 + e^(-1.702 * |x|))
        func([input_x, output], [1])
        # print(output[:10])
        # print(golden[:10])
        if compare(output, golden):
            print(f"{dtype}成功")
        print("----------------------------")
    


if __name__ == "__main__":
    main()
